
<template>
  <div class="tenantMenu_main main_container">
    <div v-loading="loading" style="margin:0;" class="main_main">
      <div class="SearchBar_main main_main_search">
        <!--        <div class="main_main_search_item">-->
        <!--          <div class="formItem_header">-->
        <!--            <div class="formItem_header_operate">-->
        <!--              <a class="formItem_header_operate_items" @click="add">-->
        <!--                <svg-icon icon-class="新增" />-->
        <!--                <div class="item_name">新增</div>-->
        <!--              </a>-->
        <!--            </div>-->
        <!--          </div>-->
        <!--        </div>-->
        <div class="main_main_search_item ">
          <el-input v-model="pageData.searchValue" style="margin-right:10px" placeholder="请输入分类编码或分类名称" clearable @keyup.enter.native="getList" @clear="getList" />
          <el-button style="background:#387bfc;width:35px;" icon="el-icon-search" @click.stop="getList" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"
          stripe
          border
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @sort-change="(column)=>{sortChange(column, this)}"
          @row-click="singleElection"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
    <div class="addtype-main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list } from '@/api/warehouseManagement/materialType'
import AddOrUpdate from './addOrUpdate' // 新增或编辑页面
export default {
  name: 'Index',
  props: {
    id: {},
    layerid: {}
  },
  data() {
    return {
      loading: true,
      pageId: '备件类型',
      pageData: {
        companyName: undefined,
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        searchValue: ''
        // status: 1
      },
      total: 1, // 数据一共有多少条
      mainId: 'id',
      tableHeight: '0',
      tableData: [],
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '分类编码' },
        { prop: 'name', label: '分类名称' },
        { prop: 'remark', label: '备注' }
      ],
      templateSelection: undefined,
      selectionsRow: {}
    }
  },
  computed: {
    // 分页器
    selectedNum() {
      return this.$refs.table ? this.$refs.table.selection.length : 0
    }
  },
  mounted() {
    this.getList()
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
    if (this.id) {
      this.templateSelection = this.id
    }
  },
  methods: {
    tableRowClass({ row }) {
      if (row.id == this.templateSelection) {
        return 'rowSelected'
      } else {
        console.log(row)
        return ''
      }
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {}// props
        },
        area: ['440px', '500px'],
        title: '新增物料分类', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    singleElection(row) {
      this.$parent.showType(row)
      this.$layer.close(this.layerid)// 关闭弹框
    },
    cancel() {
      this.$layer.close(this.layerid)// 关闭弹框
    }
  }
}
</script>

<style lang="less" scoped>
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
.addtype-main_bottom{
  padding-right: 20px !important;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search_item{
  padding-left: 20px !important;
  width: 270px !important;
//   display: flex;
//   flex-direction: row;
//   align-items: center;
//   justify-content: flex-end;
}
.main_main{
  margin: 0 !important;
  height: calc(100% - 50px);
}
</style>

